/*
 * This source code is part of TWaver 4.0
 *
 * Serva Software PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 * Copyright 2002 - 2011 Serva Software. All rights reserved.
 */

package demo.network.miscellaneous.office;

import java.awt.Color;

import twaver.AlarmSeverity;
import twaver.Follower;
import twaver.Link;
import twaver.TDataBox;
import twaver.TWaverConst;
import twaver.base.OrthogonalLinkDirectionType;
import twaver.Node;
import twaver.network.TNetwork;
import demo.DemoPane;

public class OfficeDemo extends DemoPane {

    TDataBox box = new TDataBox();
    TNetwork network = new TNetwork(box);

    public OfficeDemo() {
        this.add(network);
        network.setColorBackground(Color.white);

        BusLink bus = new BusLink(400, 20);
        bus.setName("Ether Net");
        bus.putBodyColor(new Color(132, 172, 212));
        bus.putLabelPosition(TWaverConst.POSITION_CENTER);
        bus.putLabelHighlightable(false);
        bus.putLabelColor(Color.white);
        bus.setLocation(210, 270);
        box.addElement(bus);

        Node node1 = new Node();
        node1.setImage("/demo/network/miscellaneous/office/1.png");
        node1.setLocation(330, 300);
        node1.setName("Application Server");
        box.addElement(node1);

        Node node2 = new Node();
        node2.setImage("/demo/network/miscellaneous/office/2.png");
        node2.setLocation(460, 300);
        node2.setName("Proxy Server");
        box.addElement(node2);

        Link link1 = new Link(bus, node1);
        link1.setLinkType(TWaverConst.LINK_TYPE_ORTHOGONAL);
        link1.putLinkOrthogonalDirection(OrthogonalLinkDirectionType.Y_TO_X);
        link1.putLinkWidth(1);
        link1.putLinkOutlineWidth(0);
        link1.putLinkColor(Color.gray);
        box.addElement(link1);
        Link link2 = new Link(bus, node2);
        link2.setLinkType(TWaverConst.LINK_TYPE_ORTHOGONAL);
        link2.putLinkOrthogonalDirection(OrthogonalLinkDirectionType.Y_TO_X);
        link2.putLinkWidth(1);
        link2.putLinkOutlineWidth(0);
        link2.putLinkColor(Color.gray);
        box.addElement(link2);

        Node internet = new Node();
        internet.setImage("/demo/network/miscellaneous/office/internet.png");
        internet.setLocation(40, 290);
        internet.setName("Internet");
        internet.putLabelPosition(TWaverConst.POSITION_CENTER);
        internet.putLabelHighlightable(false);
        box.addElement(internet);

        Node pstn = new Node();
        pstn.setImage("/demo/network/miscellaneous/office/pstn.png");
        pstn.setLocation(50, 100);
        pstn.setName("PSTN");
        pstn.putLabelPosition(TWaverConst.POSITION_CENTER);
        pstn.putLabelHighlightable(false);
        box.addElement(pstn);

        Node switcher = new Node();
        switcher.setImage("/demo/network/miscellaneous/office/switch.png");
        switcher.setLocation(220, 150);
        switcher.setName("Phone Switch");
        switcher.putLabelPosition(TWaverConst.POSITION_TOP);
        box.addElement(switcher);

        Node node = new Node();
        node.setImage("/demo/network/miscellaneous/office/5.png");
        node.setLocation(220, 220);
        box.addElement(node);

        Link link = new Link(switcher, node);
        link.setLinkType(TWaverConst.LINK_TYPE_ORTHOGONAL);
        link.putLinkOrthogonalDirection(OrthogonalLinkDirectionType.Y_TO_X);
        link.putLinkWidth(1);
        link.putLinkOutlineWidth(0);
        link.putLinkColor(Color.gray);
        box.addElement(link);

        link = new Link(bus, node);
        link.setLinkType(TWaverConst.LINK_TYPE_ORTHOGONAL);
        link.putLinkOrthogonalDirection(OrthogonalLinkDirectionType.Y_TO_X);
        link.putLinkWidth(1);
        link.putLinkOutlineWidth(0);
        link.putLinkColor(Color.gray);
        box.addElement(link);

        for (int i = 0; i < 3; i++) {
            Follower pc = new Follower();
            pc.setImage("/demo/network/miscellaneous/office/3.png");
            pc.setLocation(310 + i * 90, 200);
            box.addElement(pc);

            link = new Link(bus, pc);
            link.setLinkType(TWaverConst.LINK_TYPE_ORTHOGONAL);
            link.putLinkOrthogonalDirection(OrthogonalLinkDirectionType.Y_TO_X);
            link.putLinkWidth(1);
            link.putLinkOutlineWidth(0);
            link.putLinkColor(Color.gray);
            box.addElement(link);

            Follower phone = new Follower();
            phone.setImage("/demo/network/miscellaneous/office/4.png");
            phone.setLocation(290 + i * 90, 205);
            box.addElement(phone);
            phone.getAlarmState().addAcknowledgedAlarm(AlarmSeverity.getByValue(100 * i));

            phone.setHost(pc);
            pc.setHost(phone);

            link = new Link(switcher, phone);
            link.setLinkType(TWaverConst.LINK_TYPE_ORTHOGONAL);
            link.putLinkOrthogonalDirection(OrthogonalLinkDirectionType.Y_TO_X);
            link.putLinkWidth(1);
            link.putLinkOutlineWidth(0);
            link.putLinkColor(Color.green.darker());
            box.addElement(link);
        }

        node = new Node();
        node.setLocation(400, 100);
        node.getAlarmState().setNewAlarmCount(AlarmSeverity.CRITICAL, 10);
        node.setName("OSS");
        box.addElement(node);

        link = new Link(node, switcher);
        link.setLinkType(TWaverConst.LINK_TYPE_ORTHOGONAL);
        link.putLinkOrthogonalDirection(OrthogonalLinkDirectionType.Y_TO_X);
        link.putLinkWidth(1);
        link.putLinkOutlineWidth(0);
        link.putLinkColor(Color.gray);
        box.addElement(link);

        Node wall = new Node();
        wall.setImage("/demo/network/miscellaneous/office/6.png");
        wall.setLocation(250, 340);
        box.addElement(wall);

        link = new Link(node1, wall);
        link.setLinkType(TWaverConst.LINK_TYPE_ORTHOGONAL);
        link.putLinkOrthogonalDirection(OrthogonalLinkDirectionType.Y_TO_X);
        link.putLinkWidth(1);
        link.putLinkOutlineWidth(0);
        link.putLinkColor(Color.gray);
        box.addElement(link);

        Link zigzag1 = new Link(internet, wall);
        zigzag1.setLinkType(TWaverConst.LINK_TYPE_ZIGZAG);
        zigzag1.putLinkWidth(5);
        zigzag1.putLinkColor(Color.yellow);
        box.addElement(zigzag1);
        
        Link zigzag2 = new Link(pstn, switcher); 
        zigzag2.setLinkType(TWaverConst.LINK_TYPE_ZIGZAG);
        zigzag2.putLinkWidth(5);
        zigzag2.putLinkColor(Color.yellow);
        box.addElement(zigzag2);
    }

}